package com.zl.controller;

import com.zl.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.util.UUID;

/**
 * @author zl
 * @date 2023/3/21
 * @apiNote
 */
@RestController
public class LoginController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/doLogin")
    public String doLogin(String name,String pwd){
        System.out.println("hello "+name+" : "+pwd);

        // 这里假设做了登录
        User user = new User(1, "小李", 23, "123456");
        //token
        String token = UUID.randomUUID().toString();
        //存起来
        redisTemplate.opsForValue().set(token,user.toString(), Duration.ofSeconds(7200));
        return token;
    }

}
